<html>
<head>
	<meta charset="UTF-8">
	<meta content="IE=edge" http-equiv="X-UA-Compatible">
	<meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" name="viewport">
	<title>2949：[Poi2001] 蚂蚁和瓢虫</title>
	<!-- css -->
	<link href="../css/base.min.css" rel="stylesheet">
	<link href="../css/project.min.css" rel="stylesheet">
	
	<!-- favicon -->
	<!-- ... -->
</head>
<body class="page-brand">
	<header class="header header-transparent header-waterfall ui-header">
		<ul class="nav nav-list pull-left">
			<li>
				<a data-toggle="menu" href="#menu">
					<span class="icon icon-lg">menu</span>
				</a>
			</li>
		</ul>
		<a class="header-logo header-affix-hide margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">[Poi2001] 蚂蚁和瓢虫</a>
		<span class="header-logo header-affix margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">[Poi2001] 蚂蚁和瓢虫</span>
	</header>
	<nav aria-hidden="true" class="menu" id="menu" tabindex="-1">
		<div class="menu-scroll">
			<div class="menu-content">
				<a class="menu-logo" href="../index.html">BZOJ离线题库</a>
				<ul class="nav">
					<li>
						<a class="waves-attach" data-toggle="collapse" href="#problems">题目</a>
						<ul class="menu-collapse collapse in" id="problems">
							<li>
								<a class="waves-attach" href="../index.html">主页</a>
							</li>
							<li>
								<a class="waves-attach" href="../list.html">题目列表</a>
							</li>
						</ul>
					</li>
					<li>
						<a class="collapsed waves-attach" data-toggle="collapse" href="#about">关于</a>
						<ul class="menu-collapse collapse" id="about">
							<li>
								<a class="waves-attach" href="../about.html">关于此项目</a>
							</li>
						</ul>
					</li>
					
				</ul>
			</div>
		</div>
	</nav>
	<main class="content">
		<div class="content-header ui-content-header">
			<div class="container">
				<h1 class="content-heading">
                [Poi2001] 蚂蚁和瓢虫                </h1>
                <p>时间限制：10s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  空间限制：128MB</p>			</div>
		</div>
		<div class="container">
			<section class="content-inner margin-top-no">
				<div class="row">
					<div class="col-lg-13 col-md-13">
						<div class="card margin-bottom-no">
							<div class="card-main">
								<div class="card-inner">
									
                                <h3>题目描述</h3><p><div><span style="font-size: medium">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 蚂蚁和蚜虫是共生的。蚜虫分泌出蜜汁给蚂蚁引用。蚂蚁帮助蚜虫赶走它的天敌&mdash;&mdash;瓢虫。在蚂蚁山附近有一个树，这里是蚜虫生活的地方。蚜虫吸取树的汁液。有n个蚂蚁兵，用1到n编号。一个瓢虫威胁着这个文明，它经常出现在蚜虫活动的地方。当瓢虫坐在树上时，蚂蚁兵会出动把它赶走。他们按照如下的规则：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></div>
<div style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt"><span style="font-size: medium">l<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>树上的任意两点之间都只有一条路径,所有的蚂蚁都沿着它所在点到瓢虫的路径前进，每移动一个位置，花的时间是单位1。</span></div>
<div style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt"><span style="font-size: medium">l<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>如果蚂蚁和瓢虫在同一个位置，那么蚂蚁立即把它赶走。</span></div>
<div style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt"><span style="font-size: medium">l<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>如果某个蚂蚁的路径上有另外一只蚂蚁，那么距离目标较远的蚂蚁待在原地不动，较近的那个蚂蚁继续前进。</span></div>
<div style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt"><span style="font-size: medium">l<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>如果有多个蚂蚁要进入同一个位置，那么选择编号最小的蚂蚁，其余的蚂蚁留在原位置不动。</span></div>
<div style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt"><span style="font-size: medium">l<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>当蚂蚁到达了瓢虫的位置以后，把它赶走，然后停留在该位置。</span></div>
<div><span style="font-size: medium">&nbsp;</span></div>
<div style="text-indent: 21pt"><span style="font-size: medium">瓢虫是非常顽固的动物，它被赶走了以后还会再停留到别的位置。然后蚂蚁继续行动。为了使问题简单化，我们假定从一个位置到达与它相邻的位置花1个单位的时间。</span></div>
<div><span style="font-size: medium">&nbsp;</span></div>
<div><span style="font-size: medium">任务：</span></div>
<div><span style="font-size: medium">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 读入树的描述，蚂蚁的开始位置，以及瓢虫停留地点。</span></div>
<div><span style="font-size: medium">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 给出每个蚂蚁的最后的位置，以及该蚂蚁赶走瓢虫的次数。</span></div>
<div><span style="font-size: medium">&nbsp;</span></div></p><hr/><h3>输入格式</h3><p><div><span style="font-size: medium">第一行，一个整数n，1&lt;=<i>n</i>&lt;=5000。表示地点的编号。接下来n-1行描述了树里的边，每行两个整数a和b，表示这两点之间相连。然后一行是整数k，1&lt;=<i>k</i>&lt;=1000 and <i>k</i>&lt;=<i>n</i>。是蚂蚁兵的数目。接下来k行，每行一个整数，表示蚂蚁兵开始的位置。没有两个蚂蚁位于一个位置。然后是一个整数<i>l</i>, 1&lt;=<i>l</i>&lt;=500,即瓢虫停留l次。下面的l行每行一个整数，表示瓢虫依次停留的位置。</span></div>
<div><span style="font-size: medium">&nbsp;</span></div></p><hr/><h3>输出格式</h3><p><div><span style="font-size: medium">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; k行。每行两个整数，分别表示第k个蚂蚁最后的位置以及它赶走瓢虫的次数。</span></div></p><hr/><h3>样例输入</h3><pre>4
1 2
1 3
2 4
2
1
2
2
2
4
</pre><hr/><h3>样例输出</h3><pre>1 0
4 2
</pre><hr/><h3>提示</h3><p>没有写明提示</p><hr/><h3>题目来源</h3><p>没有写明来源</p>
								</div>
							</div>
						</div>
					</div>
				</div>
				
				
			</section>
		</div>
	</main>

	<div class="fbtn-container">
		<div class="fbtn-inner">
			<a class="fbtn fbtn-lg fbtn-brand-accent waves-attach waves-circle waves-light waves-effect" data-toggle="dropdown" aria-expanded="true"><span class="fbtn-text fbtn-text-left">Menu</span><span class="fbtn-ori icon">apps</span><span class="fbtn-sub icon">close</span></a>
			<div class="fbtn-dropup">
				<a class="fbtn fbtn-brand waves-attach waves-circle waves-light waves-effect" href="../list.html" target="_self"><span class="fbtn-text fbtn-text-left">题目列表</span><span class="icon">menu</span></a>
				<a class="fbtn fbtn-green waves-attach waves-circle waves-effect" href="../index.html" target="_self"><span class="fbtn-text fbtn-text-left">返回主页</span><span class="icon">home</span></a>
				<a class="fbtn waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/submitpage.php?id=2949" target="_blank"><span class="fbtn-text fbtn-text-left">提交代码</span><span class="icon">send</span></a>
				<a class="fbtn fbtn-orange waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/wttl/wttl.php?pid=2949" target="_blank"><span class="fbtn-text fbtn-text-left">试题讨论</span><span class="icon">chat</span></a>
				
			</div>
		</div>
	</div>

	<!-- js -->
	<script src="../js/jquery.min.js"></script>
	<script src="../js/base.min.js"></script>
	<script src="../js/project.min.js"></script>
</body>
</html>